package game.gui;

import game.controller.DisplayController;
import game.controller.GameController;
import game.util.GameMsg;

import javax.swing.*;
import java.awt.*;

/**
 * RoundTurn.java  Date Created: Oct 24, 2012
 *
 * Purpose: To display the current round and turn.
 *
 * Description: This panel shall display the current round and
 * whose turn it is.  It shall also display when the next production
 * round will occur.
 *
 * @author Chrisb
 */
public class RoundTurn extends JPanel {

    public RoundTurn(GameController controller, DisplayController display) {
        super();
        this.controller = controller;
        this.display = display;

        createComponents();
        layoutComponents();

        setBackground(Color.GRAY);
        setPreferredSize(new Dimension(225,175));
        setMaximumSize(new Dimension(225,175));
        setMinimumSize(new Dimension(225,175));
        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 4), BorderFactory.createEmptyBorder(10,10,10,10)));
    }

    private void createComponents() {
        roundLabel = new JLabel(GameMsg.getString("rt.roundLabel"));
        turnLabel = new JLabel(GameMsg.getString("rt.turnLabel"));
        productionRoundLabel = new JLabel(GameMsg.getString("rt.productionRoundLabel"));

        round = new JLabel(controller.getRoundYear());
        turn = new JLabel(GameMsg.getString("nation." + controller.getTurn()));
        productionRound = new JLabel(controller.getProductionRound());

        round.setForeground(Color.LIGHT_GRAY);
        turn.setForeground(Color.LIGHT_GRAY);
        productionRound.setForeground(Color.LIGHT_GRAY);
    }

    private void layoutComponents() {

        JPanel roundPanel = new JPanel();
        roundPanel.setBackground(Color.GRAY);
        roundPanel.setLayout(new BoxLayout(roundPanel, BoxLayout.LINE_AXIS));

        JPanel turnPanel = new JPanel();
        turnPanel.setBackground(Color.GRAY);
        turnPanel.setLayout(new BoxLayout(turnPanel, BoxLayout.LINE_AXIS));

        JPanel productionLabelPanel = new JPanel();
        productionLabelPanel.setBackground(Color.GRAY);
        productionLabelPanel.setLayout(new BoxLayout(productionLabelPanel, BoxLayout.LINE_AXIS));

        JPanel productionPanel = new JPanel();
        productionPanel.setBackground(Color.GRAY);
        productionPanel.setLayout(new BoxLayout(productionPanel, BoxLayout.LINE_AXIS));

        Dimension colSpacing = new Dimension(15,0);
        Dimension rowSpacing = new Dimension(0,15);

        roundPanel.add(Box.createHorizontalGlue());
        roundPanel.add(roundLabel);
        roundPanel.add(Box.createRigidArea(colSpacing));
        roundPanel.add(round);
        roundPanel.add(Box.createHorizontalGlue());

        turnPanel.add(Box.createHorizontalGlue());
        turnPanel.add(turnLabel);
        turnPanel.add(Box.createRigidArea(colSpacing));
        turnPanel.add(turn);
        turnPanel.add(Box.createHorizontalGlue());

        productionLabelPanel.add(Box.createHorizontalGlue());
        productionLabelPanel.add(productionRoundLabel);
        productionLabelPanel.add(Box.createHorizontalGlue());

        productionPanel.add(Box.createHorizontalGlue());
        productionPanel.add(productionRound);
        productionPanel.add(Box.createHorizontalGlue());

        add(roundPanel);
        add(Box.createRigidArea(rowSpacing));
        add(turnPanel);
        add(Box.createRigidArea(rowSpacing));
        add(Box.createRigidArea(rowSpacing));
        add(productionLabelPanel);
        add(Box.createRigidArea(rowSpacing));
        add(productionPanel);
    }

    public void setRoundYear(String roundYear) { round.setText(roundYear); }
    public void setTurn(String nation) { turn.setText(nation); }
    public void setProductionRound(String round) { productionRound.setText(round); }

    private JLabel roundLabel;
    private JLabel turnLabel;
    private JLabel productionRoundLabel;

    private JLabel round;
    private JLabel turn;
    private JLabel productionRound;

    private GameController controller;
    private DisplayController display;
}